/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RemoveUserScreen.java
 *
 * Created on Jun 8, 2011, 3:29:28 PM
 */

package forumGUI;

import client.ForumClientListener;
import client.TcpClient;
import javax.swing.JOptionPane;
import messaage.AddedForumMsg;
import messaage.AddedFriendMsg;
import messaage.AddedPostMsg;
import messaage.ConnectedMsg;
import messaage.CreatedThreadMsg;
import messaage.DisconnectedMsg;
import messaage.EditedPostMsg;
import messaage.ErrorMsg;
import messaage.GetListOfForumsMsg;
import messaage.GotFriendsListMsg;
import messaage.GotListOfForumsMsg;
import messaage.GotThreadMsg;
import messaage.GotTopicsOfForumMsg;
import messaage.LoggedInMsg;
import messaage.LoggedOffMsg;
import messaage.RegisteredMsg;
import messaage.RemoveUserMsg;
import messaage.RemovedForumMsg;
import messaage.RemovedFriendMsg;
import messaage.RemovedPostMsg;
import messaage.RemovedThreadMsg;
import messaage.RemovedUserMsg;

/**
 *
 * @author Olga
 */
public class RemoveUserScreen extends javax.swing.JFrame {

    private TcpClient client;
    private String username;

    /** Creates new form RemoveUserScreen */
    public RemoveUserScreen(TcpClient _client, String _username) {
        initComponents();
        this.client = _client;
        this.username = _username;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        RemoveUserLabel = new javax.swing.JLabel();
        userToRemoveTextField = new javax.swing.JTextField();
        removeButton = new javax.swing.JButton();
        backToForumsButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        RemoveUserLabel.setFont(new java.awt.Font("Viner Hand ITC", 0, 48));
        RemoveUserLabel.setText("Remove user");

        userToRemoveTextField.setText("type username to remove");

        removeButton.setFont(new java.awt.Font("Tempus Sans ITC", 1, 18));
        removeButton.setText("Remove");
        removeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeButtonActionPerformed(evt);
            }
        });

        backToForumsButton.setFont(new java.awt.Font("Tempus Sans ITC", 1, 18));
        backToForumsButton.setText("Back to forums");
        backToForumsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backToForumsButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(RemoveUserLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(userToRemoveTextField, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(removeButton)
                        .addGap(18, 18, 18)
                        .addComponent(backToForumsButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(RemoveUserLabel)
                .addGap(11, 11, 11)
                .addComponent(userToRemoveTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(removeButton)
                    .addComponent(backToForumsButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
  
      String name = this.userToRemoveTextField.getText();
      System.out.println("name = "+name);
      if (name != null && !name.isEmpty()){
          this.client.sendMessage(new RemoveUserMsg(this.username, name));
          this.setVisible(false);
      }
      else {
            	String body = "Name of user cannot be empty";
            	JOptionPane.showMessageDialog(this, body);
            }
}//GEN-LAST:event_removeButtonActionPerformed

    private void backToForumsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backToForumsButtonActionPerformed
	this.setVisible(false);
    }//GEN-LAST:event_backToForumsButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
               // new RemoveUserScreen().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel RemoveUserLabel;
    private javax.swing.JButton backToForumsButton;
    private javax.swing.JButton removeButton;
    private javax.swing.JTextField userToRemoveTextField;
    // End of variables declaration//GEN-END:variables

}
